<?php
class Business_Message
{
    protected $_tableName = 'message';
    
    protected $_tableJoinName = "reply";
    
    public function get($page = 1, $rowCount = 1, $isshow = 1)
    {

        
    	$fieldsTa = array(
            "id", "mtime", "title", "content", "homepage",
            "username", "email", "qq", "head", "isshow"
    	);
    	$fieldsTb = array("reply");
    	$select = Db_Factory::getInstance()->createSelect();
    	$select->from(array('ta' => $this->_tableName), $fieldsTa)
    	        ->joinLeft(array('tb' => $this->_tableJoinName), 'ta.id=tb.messageid', $fieldsTb)
    	        ->where('isshow = ?', $isshow)
    	        ->limitPage($page, $rowCount)
    	        ->order("id DESC");
    	$stmt = $select->query();
    	$result = $stmt->fetchAll();
    	return $result;
    }
    
    public function getAmount($isshow = 1)
    {
    	$select = Db_Factory::getInstance()->createSelect();
    	$select->from($this->_tableName, "count(*) as count")
    	        ->where('isshow = ?', $isshow);
    	$stmt = $select->query();
    	$result = $stmt->fetch();
    	$count = isset($result['count']) ? $result['count'] : 0;
    	return $count;
    }
    
    function insert($data)
    {
    	$data['ctime'] = $data['mtime'] = date("Y-m-d H:i:s");
    	$table = Db_Factory::getInstance()->createTable($this->_tableName);
    	return $table->insert($data);
    }
}